# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/30 下午5:04
 @Author  : tgy
 
"""

class MyInt:
    ...
    def __init__(self,val):
        self.val = val

    def __add__(self, other):
        if isinstance(other,MyInt):
            return MyInt(self.val + other.val)

        return MyInt(self.val+ int(other))

    def __radd__(self, other):
        if isinstance(other, MyInt):
            return MyInt(self.val + other.val)

        return MyInt(self.val + int(other))

    def __iadd__(self, other):
        if isinstance(other, MyInt):
             self.val+=other.val
        else:
            self.val += int(other)
        return self

    def __repr__(self):
        return f'val = {self.val}'

    # 当属性不存在时，调用下面这个方法
    def __getattr__(self, item):
        return "a"


if __name__ == '__main__':
    ...
    mi = MyInt(10)
    mi1 = MyInt(20)
    # print(mi + 1)
    # print(1 + mi)
    # print(mi + mi1)
    mi+=mi1
    print(mi)
    print(mi.PPP)